#include <iostream>
#include <string>
#include <jsoncpp/json/json.h>
int main()
{

    Json::Value root;
    root["name"] = "joe";
    root["sex"] = "男";
    // Json::FastWriter writer;
    Json::StyledWriter writer;
    std::string s = writer.write(root);
    // std::cout << s << std::endl;
    //return 0;

    Json::Reader reader;
    Json::Value rroot;

    bool parsingSuccessful = reader.parse(s, rroot);
    if (!parsingSuccessful)
    {
        // 解析失败，输出错误信息
        std::cout << "Failed to parse JSON: " << reader.getFormattedErrorMessages() << std::endl;
        return 1;
    }
    std::string name = rroot["name"].asCString();
    std::string sex = rroot["sex"].asCString();
    std::cout << name << std::endl;
    std::cout << sex << std::endl;

    // Json::Value root;
    // root["name"] = "joe";
    // root["sex"] = "男";
    // Json::StreamWriterBuilder wbuilder; // StreamWriter 的工厂

    // std::unique_ptr<Json::StreamWriter>
    //     writer(wbuilder.newStreamWriter());
    // std::stringstream ss;
    // writer->write(root, &ss);
    // std::cout << ss.str() << std::endl;

    // Json::Value root;
    // root["name"] = "joe";
    // root["sex"] = "男";

    // std::string s = root.toStyledString();

    // std::cout << s << std::endl;
    return 0;
}